package com.rookieci.lifegame;

import android.app.Application;
import android.content.Context;
import android.os.Handler;
import android.util.TypedValue;
import android.view.View;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;

public class MyApp extends Application {
    private static MyApp app;

    public static MyApp getInstance() {
        return app;
    }

    private ExecutorService poolExecutor;
    private Handler handler;

    public void runThread(Runnable runnable) {
        poolExecutor.execute(runnable);
    }

    public void runThread(Runnable runnable, long delayed) {
        handler.postDelayed(() -> runThread(runnable), delayed);
    }

    @Override
    public void onCreate() {
        super.onCreate();

        app = this;
        handler = new Handler();
        poolExecutor = new ScheduledThreadPoolExecutor(1);
    }

    //设置圆形单击按钮
    public static void setBackgroundOfClick(Context context, View view) {
        TypedValue mTypedValue_Borderless = new TypedValue();
        context.getTheme().resolveAttribute(androidx.appcompat.R.attr.selectableItemBackgroundBorderless
                , mTypedValue_Borderless, true);
        //context.getTheme().resolveAttribute(R.attr.selectableItemBackgroundBorderless, mTypedValue_Borderless, true);
        view.setBackgroundResource(mTypedValue_Borderless.resourceId);
    }
}
